#include "linearmath/btMotionState.h"
#include <stdio.h>
#include <OgreSceneNode.h>

class MyMotionState : public btMotionState {
public:
	MyMotionState(const btTransform &initialpos, Ogre::SceneNode *node = NULL) {
		mAttachedNode = node;
		mPos1 = initialpos;
	}

	virtual ~MyMotionState() {
	}

	void setNode(Ogre::SceneNode *node) {
		mAttachedNode = node;
	}

	virtual void getWorldTransform(btTransform &worldTrans) const {
		worldTrans = mPos1;
	}

	virtual void setWorldTransform(const btTransform &worldTrans) {
		if(NULL == mAttachedNode)
			return; // silently return before we set a node
		btQuaternion rot = worldTrans.getRotation();
		mAttachedNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
		btVector3 pos = worldTrans.getOrigin();
		mAttachedNode->setPosition(pos.x(), pos.y(), pos.z());
		//printf("x:%f y:%f z:%f \n", pos.x(), pos.y(), pos.z());
	}

protected:
	Ogre::SceneNode *mAttachedNode;
	btTransform mPos1;
};